<?=isset($header) ? $header : ''?>
<?php
//header("Cache-control: private");
//$this->load->view("header2");
//print_r($post_data);

$reload_type;
if(empty($post_data["type"]) ){
    //$type = $post_data["type"];
    $reload_type ='person';
}else{
    $reload_type = $post_data["type"];
}

if(empty($post_data) ) {
	$reload_type ='person';
}

//echo $reload_type;
//類型 1中古屋 2預售 3標售

$object_case_type_data = '';
if (!empty($post_data["object_case_type"]))
    foreach ($post_data["object_case_type"] as $key => $value) {
        $object_case_type_data.=$value . ',';
    }
?>


<div id="map-canvas"></div>

<input type="hidden"  id="all_page" value="1" >
<input type="hidden"  id="reload_type" value="<?= !empty($reload_type) ? $reload_type : ''; ?>" >

<input type="hidden"  id="sctime" value="<?= !empty($post_data["sctime"]) ? $post_data["sctime"] : ''; ?>" >
<input type="hidden"  id="ectime" value="<?= !empty($post_data["ectime"]) ? $post_data["ectime"] : ''; ?>" >
<input type="hidden"  id="customer_source" value="<?= !empty($post_data["customer_source"]) ? $post_data["customer_source"] : ''; ?>" >


<input type="hidden"  id="broker" value="<?= !empty($post_data["broker"]) ? $post_data["broker"] : ''; ?>" >
<input type="hidden"  id="keywords" value="<?= !empty($post_data["keywords"]) ? $post_data["keywords"] : ''; ?>" >
<input type="hidden"  id="status" value="<?= !empty($post_data["status"]) ? $post_data["status"] : ''; ?>" >




<input type="hidden"  id="administrative_area" value="<?= !empty($post_data["administrative_area"]) ? $post_data["administrative_area"] : ''; ?>" >
<input type="hidden"  id="year_of_construction1" value="<?= !empty($post_data["year_of_construction1"]) ? $post_data["year_of_construction1"] : ''; ?>" >
<input type="hidden"  id="year_of_construction2" value="<?= !empty($post_data["year_of_construction2"]) ? $post_data["year_of_construction2"] : ''; ?>" >


<input type="hidden"  id="object_case_type" value="<?= !empty($object_case_type_data) ? $object_case_type_data : ''; ?>" >


<input type="hidden"  id="type_rent" value="<?= !empty($post_data["type_rent"]) ? $post_data["type_rent"] : ''; ?>" >
<input type="hidden"  id="type_sell" value="<?= !empty($post_data["type_sell"]) ? $post_data["type_sell"] : ''; ?>" >


<input type="hidden"  id="required_level" value="<?= !empty($post_data["required_level"]) ? $post_data["required_level"] : ''; ?>" >
<input type="hidden"  id="name" value="<?= !empty($post_data["name"]) ? $post_data["name"] : ''; ?>" >
<input type="hidden"  id="object_usage" value="<?= !empty($post_data["object_usage"]) ? $post_data["object_usage"] : ''; ?>" >
<input type="hidden"  id="building_area1" value="<?= !empty($post_data["building_area1"]) ? $post_data["building_area1"] : ''; ?>" >
<input type="hidden"  id="building_area2" value="<?= !empty($post_data["building_area2"]) ? $post_data["building_area2"] : ''; ?>" >
<input type="hidden"  id="indoor_area1" value="<?= !empty($post_data["indoor_area1"]) ? $post_data["indoor_area1"] : ''; ?>" >
<input type="hidden"  id="indoor_area2" value="<?= !empty($post_data["indoor_area2"]) ? $post_data["indoor_area2"] : ''; ?>" >
<input type="hidden"  id="land_area1" value="<?= !empty($post_data["land_area1"]) ? $post_data["land_area1"] : ''; ?>" >
<input type="hidden"  id="land_area2" value="<?= !empty($post_data["land_area2"]) ? $post_data["land_area2"] : ''; ?>" >
<input type="hidden"  id="total_budget1" value="<?= !empty($post_data["total_budget1"]) ? $post_data["total_budget1"] : ''; ?>" >
<input type="hidden"  id="total_budget2" value="<?= !empty($post_data["total_budget2"]) ? $post_data["total_budget2"] : ''; ?>" >
<input type="hidden"  id="key_areas" value="<?= !empty($post_data["key_areas"]) ? $post_data["key_areas"] : ''; ?>" >
<input type="hidden"  id="specify_building" value="<?= !empty($post_data["specify_building"]) ? $post_data["specify_building"] : ''; ?>" >
<input type="hidden"  id="object_name" value="<?= !empty($post_data["object_name"]) ? $post_data["object_name"] : ''; ?>" >

<input type="hidden"  id="sections1" value="<?= !empty($post_data["sections1"]) ? $post_data["sections1"] : ''; ?>" >
<input type="hidden"  id="sections2" value="<?= !empty($post_data["sections2"]) ? $post_data["sections2"] : ''; ?>" >
<span id="all_selected" style="display:none;">
    <font color="red">全頁選取</font>
</span>

<div id="content" style="display:none;">





    <link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
    <link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
    <script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>




    <table class="flexme4" style="display: none"></table>



    <script type="text/javascript">

                $(".flexme4").flexigrid({
                url : '<?=($reload_type =='company')?'/dem/demandresult/crid_josn':'/dem/person/crid_josn'; ?>',
                dataType : 'json',
                colModel : [ 
                {
                display : '編號',
                        name : 'demand_id',
                        width : '90',
                        sortable : true,
                        align : 'center'
                }
                ,
                {
                display : '建物面積',
                        name : 'building_area1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                }
                ,
                
                {
                display : '土地面積',
                        name : 'land_area1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                }
                ,
                
                {
                display : '總預算',
                        name : 'total_budget1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                }
                ,                
                {
                display : '重點區域',
                        name : 'key_areas1',
                        width : 70,
                        sortable : true,
                        align : 'left'
                }
                ,                                
                {
                display : '屋齡',
                        name : 'year_of_construction',
                        width : 30,
                        sortable : true,
                        align : 'left'
                }
                ,
                {
                display : '物件用途',
                        name : 'object_usage',
                        width : 180,
                        sortable : true,
                        align : 'left'
                },
                <?php if($reload_type=='person'){?>
                {
                display : '客戶姓名',
                        name : 'name',
                        width : 100,
                        sortable : true,
                        align : 'left'
                }
                ,
                {
                display : '特徴',
                        name : 'recommended',
                        width : 80,
                        sortable : false,
                        align : 'left'
                }
                ,
                {
                display : '建檔日期',
                        name : 'ctime',
                        width : 90,
                        sortable : false,
                        align : 'left'
                }
                ,
                <?php } ?>
                {
                display : '需求類型',
                        name : 'type_rent',
                        width : 100,
                        sortable : true,
                        align : 'left'
                },
                
                
<?php if ($reload_type == "company") { ?>
                    ,
                    {
                    display : '經紀人',
                            name : 'broker',
                            width : 180,
                            sortable : true,
                            align : 'left'
                    }

<?php } ?>
                ],
                buttons : [
                {
                name : '配對',
                        bclass : 'pattern',
                        onpress : Example4
                },
<?php
if (check_menu_permissios("demand_data_edit")) {
    ?>
                    {
                    name : '編輯',
                            bclass : 'edit',
                            onpress : Example4
                    }
                    ,
<?php } ?>
               
                {
                name : '全頁選取',
                        bclass : 'coffee',
                        onpress : Example4
                }
                ,
                 {
                name : 'Excel',
                        bclass : 'coffee',
                        onpress : Example4
                }
                
                
                ,
<?php
if (check_menu_permissios("demand_data_delete")) {
    ?>
                    {
                    name : '删除',
                            bclass : 'delete',
                            onpress : Example4
                    }
                    ,
<?php } ?>
                {
                separator : true
                }
                ],
                sortname : "demand_id",
                sortorder : "desc",
                usepager : true,
                title : '需求列表',
                checkbox : true, // 是否要多選框
                useRp : true,
                rp : 10,
                width: 'auto',
                height: 'auto',
                procmsg:'資料讀取中，請稍後…',
                nomsg:'找不到符合絛件的資料',
                //margin: 10px 1palex 1px -53px
        });
                function Example4(com, grid) {

                if (com == '删除') {


                var empty_str = '';
                        var _fg = true;
                        $(".trSelected").each(function() {

                var str = $(this).children().next().html();
                        var str2 = str.split('</div>');
                        var str = str2[0].split('>');
                        if (_fg){

                _fg = false;
                        empty_str += parseInt(str[1]);
                } else{

                empty_str += "," + parseInt(str[1]);
                }
                });
                        $.post('/demand/save_demand_id', {

                        id : empty_str,
                                is_del : '0'

                        }, function(data) {

                        $.post('/demand/del_demand_id', {

                        }, function(data) {
                        $(".flexme4").flexReload();
                        });
                        });
                } else if (com == '編輯') {



                    $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                            var str2 = str.split('</div>');
                            var str = str2[0].split('>');
                            var url = '/demand/data_edit?id=' + parseInt(str[1])+"&type="+'<?=$reload_type?>';
                            document.location.href = url;
                    });
                    }
                    else if (com == '配對') {
                        var tr_ed = $('.trSelected', grid).length;
                            if (tr_ed == 1){

                    $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                                var str2 = str.split('</div>');
                                var str = str2[0].split('>');
                                var url = '/pair/demand?id=' + parseInt(str[1]);
                                document.location.href = url;
                        });
                    } else{
                        alert('一次只能選取一個');
                    }
                }
                else if (com == 'Add') {

                }
                else if (com == '全頁選取') {
                    var _flag = $("#all_page").val();

                    //alert(_flag);
                    if(_flag=='1'){
                        $("#all_selected").show();
                        $("#all_page").val('2');
                    }else {
                        $("#all_selected").hide();
                        $("#all_page").val('1');
                    }

                }
                else if (com == 'Excel') { 

                    var _flag = $("#all_page").val();
                    var _type = $("#type").val();
                    var empty_str = '';
                    var _fg = true;

                    if(parseInt(_flag)==2 ){
                        
                        if(_type=='person'){

                            $("#all_page").after('個人');
                            var url = '/demand/do_all_excel?type=person';
                            document.location.href = url;

                        }else{

                            $("#all_page").after('公司');
                            var url = '/demand/do_all_excel?type=company';
                            document.location.href = url;
                        }


                    }else{

                        $(".trSelected").each(function() {

                        var str = $(this).children().next().html();
                                var str2 = str.split('</div>');
                                var str = str2[0].split('>');
                                if (_fg){
                            _fg = false;
                                empty_str += parseInt(str[1]);
                            } else{
                                empty_str += "," + parseInt(str[1]);
                            }
                        });
                        $.post('/demand/save_demand_id', {
                                id : empty_str,
                                is_del : '0'
                        }, function(data) {

                                var url = '/demand/excel';
                                document.location.href = url;
                        });
                    }
                }



                }






        function query() {


        var name = $("#name").val();
                var type_sell = $("#type_sell").val();
                var type_rent = $("#type_rent").val();
                var required_level = $("#required_level").val();
                var object_usage = $("#object_usage").val();
                var building_area1 = $("#building_area1").val();
                var building_area2 = $("#building_area2").val();
                var indoor_area1 = $("#indoor_area1").val();
                var indoor_area2 = $("#indoor_area2").val();
                var land_area1 = $("#land_area1").val();
                var land_area2 = $("#land_area2").val();
                var total_budget1 = $("#total_budget1").val();
                var total_budget2 = $("#total_budget2").val();
                var key_areas = $("#key_areas").val();
                var specify_building = $("#specify_building").val();
                var object_name = $("#object_name").val();
                var sections1 = $("#sections1").val();
                var sections2 = $("#sections2").val();
                var _type = 'person';
                var object_case_type = $("#object_case_type").val();
                var administrative_area = $("#administrative_area").val();
                var year_of_construction1 = $("#year_of_construction1").val();
                var year_of_construction2 = $("#year_of_construction2").val();
                var sections1 = $("#sections1").val();
                var sections2 = $("#sections2").val();
                var _type = 'person';
                var object_case_type = $("#object_case_type").val();
                var administrative_area = $("#administrative_area").val();
                var year_of_construction1 = $("#year_of_construction1").val();
                var year_of_construction2 = $("#year_of_construction2").val();
                //alert(administrative_area);


                var status = $("#status").val();
                var keywords = $("#keywords").val();
                var broker = $("#broker").val();
                var customer_source = $("#customer_source").val();
                var ectime = $("#ectime").val();
                var sctime = $("#sctime").val();

                var reload_type = $("#reload_type").val();
                //alert(type);

                $(".flexme4").flexOptions(
        {newp: 1, params:
                [
                {name: 'sctime',
                        value: sctime}
                ,
                {name: 'reload_type',
                        value: reload_type}
                ,
                {name: 'ectime',
                        value: ectime}
                ,
                {name: 'customer_source',
                        value: customer_source}
                ,
                {name: 'broker',
                        value: broker}
                ,
                {name: 'keywords',
                        value: keywords}
                ,
                {name: 'status',
                        value: status}
                ,
                {name: 'administrative_area',
                        value: administrative_area}
                ,
                {name: 'year_of_construction1',
                        value: year_of_construction1}
                ,
                {name: 'year_of_construction2',
                        value: year_of_construction2}
                ,
                {name: 'type_sell',
                        value: type_sell}
                ,
                {name: 'object_case_type',
                        value: object_case_type}
                ,
                {name: 'type_rent',
                        value: type_rent}
                ,
                {name: 'type',
                        value: _type}
                ,
                {name: 'name',
                        value: name}
                ,
                {name: 'sections1',
                        value: sections1}
                ,
                {name: 'sections2',
                        value: sections2}
                ,
                {name: 'object_name',
                        value: object_name}
                ,
                {name: 'specify_building',
                        value: specify_building}
                ,
                {name: 'key_areas',
                        value: key_areas}
                ,
                {name: 'total_budget1',
                        value: total_budget1}
                ,
                {name: 'total_budget2',
                        value: total_budget2}
                ,
                {name: 'land_area1',
                        value: land_area1}
                ,
                {name: 'land_area2',
                        value: land_area2}
                ,
                {name: 'indoor_area1',
                        value: indoor_area1}
                ,
                {name: 'indoor_area2',
                        value: indoor_area2}
                ,
                {name: 'building_area1',
                        value: building_area1}
                ,
                {name: 'building_area2',
                        value: building_area2}
                ,
                {name: 'object_usage',
                        value: object_usage}
                ,
                {name: 'required_level',
                        value: required_level}
                ]
        }).flexReload();

        
           $("#content").show(); 
        }

        $("document").ready(function() {
            //alert('qqqq');$("#content").show(); 
            //$("#content").show(); 
            setTimeout('query()', 800);

        });
    </script>
</div>
<?=
isset($footer) ? $footer : ''?>
